package yeliuhuishi.WordCount.basics;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import yeliuhuishi.File.DelAllFile;

import java.io.File;

/**
 * 统计单词个数
 * count
 */
public class WordCount {

    public static void main(String[] args) throws Exception {
        String input = "src/main/java/yeliuhuishi/WordCount/basics/input";
        String output = "src/main/java/yeliuhuishi/WordCount/basics/output";

        DelAllFile.delAllFile(new File(output));

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf, WordCount.class.getName());

        job.setJarByClass(WordCount.class);
        job.setMapperClass(myMapper.class);
        job.setReducerClass(myReduce.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        FileInputFormat.setInputPaths(job, new Path(input));

        FileOutputFormat.setOutputPath(job, new Path(output));

        System.out.println(job.waitForCompletion(true) ? "成功" : "失败");

    }
}
